	String.prototype.trim = function () {
	    return this.replace(/(^\s*)|(\s*$)/g, "");
	}
	String.prototype.ltrim = function () {
	    return this.replace(/(^\s*)/g, "");
	}
	String.prototype.rtrim = function () {
	    return this.replace(/(\s*$)/g, "");
	}
	String.prototype.getParameter = function(name) {
		var reg = new RegExp("(^|&)"+ name+"=([^&]*)(&|$)");
		var r = this.substr(this.indexOf("\?")+1).match(reg);
		if (r!=null) {
			return unescape(r[2]); 
		}
		return "";
	}
	
	//Web?OpenAgent&pageClassName=PrelimDataGroupPage&action=next&unid=123456
	function removeURLParam(urlStr,paramName){
		var matchStr="&"+paramName+"=";
		var pos=urlStr.indexOf(matchStr);
		if(pos<0){
			return urlStr;
		}
		var resultStr=urlStr.substring(0,pos);//Web?OpenAgent&pageClassName=PrelimDataGroupPage
		var tempStr=urlStr.substring(pos+1,urlStr.length);//action=next&unid=123456
		//alert("111:"+tempStr);//action=save&unid=123456
		pos=tempStr.indexOf("&");
		if(pos>=0){
			tempStr=tempStr.substring(pos,tempStr.length);//&unid=123456
			//alert("222:"+tempStr);//&unid=123456
			resultStr=resultStr+tempStr;
		}		
		return resultStr;//Web?OpenAgent&pageClassName=PrelimDataGroupPage&unid=123456
		//urlStr1:Web?OpenAgent&pageClassName=AnnouncementPage&action=save&unid=123456
		//urlStr2:Web?OpenAgent&pageClassName=AnnouncementPage&unid=123456
	}
	
	/*
	urlStr - eg: Web?OpenAgent&pageClassName=PrelimDataGroupPage&action=done
	paramNameArray - {"pageClassName","action"}
	return paramValueArray - {"PrelimDataGroupPage","done"}
	execute :
	<input type="hidden" name="pageClassName" id="pageClassName" value="" />
	<input type="hidden" name="action" id="action" value="" />
	document.getElementById("pageClassName").value="PrelimDataGroupPage";
	document.getElementById("action").value="done";
	Note:if action is blank, use default value "open"
	*/	
	function setURLParamHiddenField(urlStr,paramNameArray){
		if(paramNameArray==null || paramNameArray.length==0){
			return;
		}
		var paramValueArray=new Array();
		for(var i=0;i<paramNameArray.length;i++){
			var fieldValue=urlStr.getParameter(paramNameArray[i]);
			var fieldName=paramNameArray[i];
			if(fieldName=="action"){
				if(fieldValue==null || fieldValue.trim()==""){
					fieldValue="open";
				}
			}
			var fieldObj=document.getElementById(fieldName);			
			if(fieldObj!=null){
				fieldObj.value=fieldValue;
			}
			paramValueArray[i]=fieldValue;
		}
		return paramValueArray;
	}
	
	var OptionDataObj=function(text,value,checked){
		this.text=text;
		this.value=value;
		this.checked=checked;
	};
		
	//eg: event=change,click....
	function addEvent(el, event, handler){
		if (el.addEventListener){//Mozilla
			var eventName=event.toLowerCase();
			el.addEventListener(eventName, handler, false);	
		}else if (el.attachEvent){//IE
			var firstLetter=event.substring(0,1).toUpperCase();
			var eventName=firstLetter+event.substring(1,event.length).toLowerCase();
			el.attachEvent("on"+eventName, handler);
		}
	}	
	
	/*
	 return the nomber of table rows
	 table:	table element, or tbody element
	 */
	
	function countTableRows(table) {
	    var tableRows = table.rows;
	    if (tableRows != null) {
	        return tableRows.length;
	    } else {
	        return 0;
	    }
	}
	
	/*
	 append table rows 
	 table:		table element
	 rowData:	2-dimensional array that hold table rows
	 rowData[i] point to a 1-dimensional array which hold one row
	 sample of rowData:
	 var row0=new Array();
	 row0[0]="<p>test</p>";
	 row0[1]="<input name='test' type='checkbox' value='test'>test</input>";
	 ...
	 rowData[0]=row0;
	 */
	
	function addRecords(table, rowData) {
	    var rowNum = countTableRows(table);
	
	    for (var i = 0,rowId=rowNum; i < rowData.length; i++,rowId++) {
	        var tr = table.insertRow(rowNum);
	        if (rowId % 2 ==0){
             tr.className="odd";
          }else{
	          tr.className="even";
          }
	        rowNum++;
	        for (var j = 0; j < rowData[i].length; j++) {
	            var td = tr.insertCell(j);
	            td.innerHTML = rowData[i][j];
	        }
	    }
	}
	
	function addTableRecords(table, rowData) {
	    var rowNum = countTableRows(table);
	
	    for (var i = 0; i < rowData.length; i++) {
	        var tr = table.insertRow(rowNum);
	        rowNum++;
	        for (var j = 0; j < rowData[i].length; j++) {
	            var td = tr.insertCell(j);
	            td.innerHTML = rowData[i][j];
	        }
	    }
	}
		
	/*
	 remove all table rows 
	 table:	table element, or tbody element
	 */
	
	function removeTableRows(table) {
	    var rowNum = countTableRows(table);
	    for (var row = (rowNum - 1); row >= 0; row--) { //scan from last row
	        table.deleteRow(row);
	    }
	}
	
	/*
	 remove specified table rows 
	 table:	table element, or tbody element
	 rowIds:	1-dimensional array that hold row ids to be removed
	 */
	
	function removeRecords(table, rowIds) {
	    var rowNum = countTableRows(table);
	    for (var row = (rowNum - 1); row >= 0; row--) { //scan from last row
	        for (var i = 0; i < rowIds.length; i++) {
	            if (row == rowIds[i]) {
	                //alert("row "+i+" is deleted!");
	                table.deleteRow(row);
	            }
	        }
	    }
	}
	/*
	 update specified table rows 
	 table:	table element, or tbody element
	 rowData:	1-dimensional array that hold one row
	 rowId:		row to be updated. start from 0
	*/
	function updateTableRow(table,rowData,rowId){
		var tableRows = table.rows;
		if(rowId<0 || rowId>(tableRows.length-1)){
			return;
		}
		var tr=tableRows[rowId];
		for(var j=0;j<rowData.length;j++){
			var td=tr.cells[j];
			td.innerHTML = rowData[j];
		}
	}
	
	/*
	 update specified table cell 
	 table:	table element, or tbody element
	 cellData:	string content
	 rowId/colId:		row/Col to be updated. start from 0	 
	*/	
	function updateTableCell(table,cellData,rowId,colId){
		var tableRows = table.rows;
		if(rowId<0 || rowId>(tableRows.length-1)){
			return;
		}
		var tr=tableRows[rowId];
		if(colId<0 || colId> (tr.cells.length-1)){
			return;
		}
		var td=tr.cells[colId];			
		td.innerHTML = cellData;
	}
	
	/*
	 set table row class to odd/even 
	 table:	table element, or tbody element
	 */
	
	function setTableRowClass(table) {
	    var rowNum = countTableRows(table);
	    for (var i = 0; i < rowNum; i++) {
	        var tr = table.rows[i];
	        //alert( "row"+(i+1)+" className: "+tr.className); 
	        if ((i + 1) % 2 == 1) {
	            tr.className = "odd";
	        } else {
	            tr.className = "even";
	        }
	    }
	}
	
	function addOptions(selectObject, optionTextList, optionValueList) {
	    for (var i = 0; i < optionTextList.length; i++) {
	        var optionText = optionTextList[i];
	        var optionValue = optionValueList[i];
	        addOption(selectObject, optionText, optionValue);
	    }
	}
	
	function addOption(selectObject, optionText, optionValue) {
	    var oneOption = new Option(optionText, optionValue);
	    selectObject.options.add(oneOption);
	    return oneOption;
	}
	
	function removeSelectedOptions(selectObject) {
	    for (var i = selectObject.length - 1; i >= 0; i--) {
	        if (selectObject.options[i].selected) {
	            selectObject.remove(i);
	        }
	    }
	}
	
	function removeAllOptions(selectObject) {
	    for (var i = selectObject.length - 1; i >= 0; i--) {
	        selectObject.remove(i);
	    }
	}
	
	function removeOptions(selectObject, start, end) {
	    var startPos = 0;
	    var endPos = 0;
	    if (start != null && start >= 0) {
	        startPos = start;
	    } else {
	        startPos = 0;
	    }
	    if (end != null && end >= 0) {
	        endPos = end;
	    } else {
	        endPos = selectObject.length - 1;
	    }
	    for (var i = endPos; i >= startPos; i--) {
	        selectObject.remove(i);
	    }
	}
	
	function getSelectedOptions(selectObject) {
	    var values = new Array();
	    var id = 0;
	    for (var i = 0; i < selectObject.length; i++) {
	        if (selectObject.options[i].selected) {
	            values[id++] = selectObject.options[i].value;
	        }
	    }
	    return values;
	}
	
	//remove white blanks in a String
	
	function Jtrim(str) {
	
	    var i = 0;
	    var len = str.length;
	    if (str == "") return (str);
	    j = len - 1;
	    flagbegin = true;
	    flagend = true;
	    while ((flagbegin == true) && (i < len)) {
	        if (str.charAt(i) == " ") {
	            i = i + 1;
	            flagbegin = true;
	        } else {
	            flagbegin = false;
	        }
	    }
	
	    while ((flagend == true) && (j >= 0)) {
	        if (str.charAt(j) == " ") {
	            j = j - 1;
	            flagend = true;
	        } else {
	            flagend = false;
	        }
	    }
	
	    if (i > j) return ("");
	
	    trimstr = str.substring(i, j + 1);
	    return trimstr;
	}
	

	//to check if each character of s is in bag
	
	function isCharsInBag(s, bag) {
	    var i;
	
	    for (i = 0; i < s.length; i++) {
	        var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) return false;
	    }
	    return true;
	}
	
	function isEmpty(s) {
	    return ((s == null) || (s.length == 0));
	}
	
	function isWhitespace(s){
		return isEmpty(s);
	}
	
	//check if the string contains white spaces
	
	function isContainWhitespace(s) {
	    var whitespace = " \t\n\r";
	    var i;
	    for (i = 0; i < s.length; i++) {
	        var c = s.charAt(i);
	        if (whitespace.indexOf(c) >= 0) {
	            return true;
	        }
	    }
	    return false;
	}
	
	//leapyear check
	
	function isleapyear(thisyear) {
	    return (((thisyear % 4 == 0) && (thisyear % 100 != 0)) || (thisyear % 400 == 0))
	
	}
	
	
	//to check if one radio option in a group is checked
	
	function radioselected(radioBth) {
	    for (i = 0; i < radioBth.length; i++) {
	        if (radioBth[i].checked) return true
	    }
	    return false
	}
	
	
	//check if email address is valid
	
	function isEmail(s) {
	    if (isEmpty(s)) {
	        alert("The Email address can not be empty!");
	        return false;
	    }
	    //is s contain whitespace
	    if (isWhitespace(s)) {
	        alert("The E-mail address can not contain the white space");
	        return false;
	    }
	    var i = 1;
	    var len = s.length;
	
	    pos1 = s.indexOf("@");
	    pos2 = s.indexOf(".");
	    pos3 = s.lastIndexOf("@");
	    pos4 = s.lastIndexOf(".");
	    if ((pos1 <= 0) || (pos1 == len) || (pos2 <= 0) || (pos2 == len)) {
	        alert("Please input valid Email address!");
	        return false;
	    } else {
	        if ((pos1 == pos2 - 1) || (pos1 == pos2 + 1) || (pos1 != pos3) //find two @
	        || (pos4 < pos3)) //. should behind the '@'
	        {
	            alert("Please input valid Email address!");
	            return false;
	        }
	    }
	
	    if (!isCharsInBag(s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@")) {
	        alert("Email address only can contain the following characters:\n ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@");
	        return false;
	    }
	
	    var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|com|gov|mil|org|edu|int)$"
	    var re = new RegExp(regu);
	    if (s.search(re) != -1) {
	        return true;
	    } else {
	        window.alert("Please input valid Email address")
	        return false;
	    }
	
	    return true;
	}
	
	//To check if input is digit
	
	function isNum(s, m) {
	    if (isEmpty(s)) {
	        //alert("The input must be digits!");
	        return false;
	    }
	    if (!isCharsInBag(s, "0123456789")) {
	        //alert("The input must be digits!");
	        return false;
	    }
	
	    return true;
	}
	
	//find the character within s which is  first apperance in bag 
	
	function findFirstAppearance(s, bag) {
	    var i, c;
	    // Search through string's characters one by one.
	    // If character is in bag, append to returnString.
	    for (i = 0; i < s.length; i++) {
	        c = s.charAt(i);
	        if (bag.indexOf(c) > -1) return c;
	    }
	    return "";
	}
	
	function sortcode(punid, unid, name, code, readonly) {
	    this.punid = punid;
	    this.code = code;
	    this.name = name;
	    this.unid = unid;
	    this.readonly = readonly;
	}
	sortcode.prototype.toString = function () {
	    return "[" + "code:" + this.code + ",name:" + this.name + ",unid:" + this.unid + ",readonly:" + this.readonly + "]";
	};
	
	function categoryTreeNode(UNID, catetoryName, subCatetoryName, checkedFlag, enabledFlag) {
	    this.UNID = UNID;
	    this.catetoryName = catetoryName;
	    this.subCatetoryName = subCatetoryName;
	    this.checkedFlag = checkedFlag;
	    this.enabledFlag = enabledFlag;
	}
	categoryTreeNode.prototype.toString = function () {
	    return "[" + "UNID:" + this.UNID + ",catetoryName:" + this.catetoryName + ",subCatetoryName:" + this.subCatetoryName + ",checkedFlag:" + this.checkedFlag + ",enabledFlag:" + this.enabledFlag + "]";
	};
	
	function getIntersection(array1, array2) {
	    var intersectionArray = new Array();
	    var id = 0;
	    for (var i = 0; i < array1.length; i++) {
	        for (var j = 0; j < array2.length; j++) {
	            if (array1[i] == array2[j]) {
	                intersectionArray[id++] = array1[i];
	            }
	        } //end for				
	    } //end for
	    return intersectionArray;
	}
	
	function replaceSubstring(inputString, fromString, toString) {
	   // Goes through the inputString and replaces every occurrence of fromString with toString
	   var temp = inputString;
	   if (fromString == "") {
	      return inputString;
	   }
	   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
	      while (temp.indexOf(fromString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	         temp = toTheLeft + toString + toTheRight;
	      }
	   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
	      var midStrings = new Array("~", "`", "_", "^", "#");
	      var midStringLen = 1;
	      var midString = "";
	      // Find a string that doesn't exist in the inputString to be used
	      // as an "inbetween" string
	      while (midString == "") {
	         for (var i=0; i < midStrings.length; i++) {
	            var tempMidString = "";
	            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
	            if (fromString.indexOf(tempMidString) == -1) {
	               midString = tempMidString;
	               i = midStrings.length + 1;
	            }
	         }
	      } // Keep on going until we build an "inbetween" string that doesn't exist
	      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
	      while (temp.indexOf(fromString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	         temp = toTheLeft + midString + toTheRight;
	      }
	      // Next, replace the "inbetween" string with the "toString"
	      while (temp.indexOf(midString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(midString));
	         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
	         temp = toTheLeft + toString + toTheRight;
	      }
	   } // Ends the check to see if the string being replaced is part of the replacement string or not
	   return temp; // Send the updated string back to the user
	} // Ends the "replaceSubstring" function
		
	function getBooleanValue(value) {
		if (typeof(value)=="string"){
			if(value=="true"){
				return true;
			}else{
				return false;
			}
		}else if(typeof(value)=="boolean"){
			return value;
		}else{
			return Boolean(value);
		}
	}		
	
	function isExistingItem(objSelect,objItemValue){
	 var isExist=false;
	  for (var i = 0; i < objSelect.options.length; i++) { 
	  	 if (objSelect.options[i].value == objItemValue) {        
            isExist = true;        
            break;        	       
	 			}
	  }
	   return isExist;
	
	}
	
	function addItemToSelect(objSelect, objItemText, objItemValue) {
	  var optionsLength = objSelect.options.length;        
		if (isExistingItem(objSelect, objItemValue)==false) {
		    var varItem = new Option(objItemText, objItemValue);      
        objSelect.options[optionsLength]=varItem;     
		}
	}
	
	function clearSelect(objSelect){
	  objSelect.options.length=0; 
	}	
	
	function copyElementsFromPOPtoParent(divId, formId) {
//divid is the div in the parent window and this div will contain all of elements in the popup window
//formId is the form id in the popup window and we need to copy all fo elements into parent window and set
//the save values.
	var e;
	var pwE ;
	opener.document.getElementById(divId).innerHTML = document.getElementById(divId).innerHTML;
	formObj = document.getElementById(formId);
		for (var k = 0; k < formObj.elements.length; k++) {
	        e = formObj.elements[k];
	        try{
	          pwE = opener.document.getElementById(e.id);
	        }catch(e0){}
	        try {
	            pwE.value = e.value;
	        } catch (e1) {}
	        try {
	            pwE.checked = e.checked;
	        } catch (e2) {}
	        try {
	            for (var i = 0; i < e.length; i++) {
	                pwE[i].selected = e[i].selected;
	            }
	        } catch (e3) {}
	    }
	}
	
	function copyElementsFromPOP2Parent(divId, formId,parentWindow) {
//divid is the div in the parent window and this div will contain all of elements in the popup window
//formId is the form id in the popup window and we need to copy all fo elements into parent window and set
//the save values.
	var e;
	var pwE ;
	parentWindow.document.getElementById(divId).innerHTML = document.getElementById(divId).innerHTML;
	formObj = document.getElementById(formId);
		for (var k = 0; k < formObj.elements.length; k++) {
	        e = formObj.elements[k];
	        try{
	          pwE = opener.document.getElementById(e.id);
	        }catch(e0){}
	        try {
	            pwE.value = e.value;
	        } catch (e1) {}
	        try {
	            pwE.checked = e.checked;
	        } catch (e2) {}
	        try {
	            for (var i = 0; i < e.length; i++) {
	                pwE[i].selected = e[i].selected;
	            }
	        } catch (e3) {}
	    }
	}
	
	//to check if the current web browser TYPE
function webbrowserType(){
	var browserType ="";	
 if(navigator.userAgent.toLowerCase().indexOf("msie")>=0){
 	    if(navigator.appVersion.match(/msie 8./i) !=null) {
               browserType= "msie8";
       }else if(navigator.appVersion.match(/msie 6./i)!=null) {
             browserType= "msie6";
      }else{
      	   browserType= "msie";
      	}
 		
 }else if(navigator.userAgent.toLowerCase().indexOf("firefox")>=0){
		browserType= "firefox";
	}else if(navigator.userAgent.toLowerCase().indexOf("chrome")>=0){
		browserType= "chrome";
  }else if(navigator.userAgent.toLowerCase().indexOf("safari")>=0){
		browserType= "safari";
   }
   return browserType;
}

	//to check string only contain char
	function ischar(s) {
	    var invalidChar;
	    var specialChar = "><,[]{}?/+=|\\'\":;~!@#$%^&()`";
	    if (s == "") {
	        alert("Please input the content!")
	        return false;
	    }
	
	    if (isWhitespace(s)) {
	        alert("The content can not contain the white space!");
	        return false;
	    }
	    invalidChar = findFirstAppearance(s, specialChar);
	    if (invalidChar != "") {
	        alert("The character " + s + " you input is invalid,\n\n please remove the " + invalidChar + " in your input!");
	        return false;
	    }
	    return true;
	}
	
	function hideTableColumn(oTable, iCol){
	  if (oTable ==null){
	    return;
	  }
	  
	 	 for (var i=0;i < oTable.rows.length ; i++)   
    {   
        oTable.rows[i].cells[iCol].style.display = "none";   
    }   

	
	}
	
	
	function displayTableColumn(oTable, iCol){
	   if (oTable ==null){
	    return;
	  }
	  
	 	 for (var i=0;i < oTable.rows.length ; i++)   
    {   
        oTable.rows[i].cells[iCol].style.display = "table-cell";
        
    }   
	
	}
	
	function hideTableRow(oTable, iRow){
	  if (oTable ==null){
	    return;
	  }
	  
	 	 oTable.rows[iRow].style.display = "none";   

	}
	
	
	function displayTableRow(oTable, iRow){
	   if (oTable ==null){
	    return;
	  }
	  
	 	oTable.rows[iRow].style.display = "block";   
	
	}

  // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

	function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#ddd";
    var oddColor = arguments[2] ? arguments[2] : "#fff";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
            }
          }
		  even =  ! even;
		}
        // flip from odd to even, or vice-versa
        //even =  ! even;
      }
    }
  }
  
  
  function hideElementById(elementId){
		if(document.getElementById(elementId) !=null){
			  document.getElementById(elementId).style.display ="none";
			
			}
		}
		
	function displayElementById(elementId,styleValue){
		if(document.getElementById(elementId) !=null){
			  document.getElementById(elementId).style.display =styleValue;
			
			}
		}
		
		
		function disableElementById(elementId){
		if(document.getElementById(elementId) !=null){
			  document.getElementById(elementId).disabled=true;	
			
			}
		}
		
		function enableElementById(elementId){
		if(document.getElementById(elementId) !=null){
			  document.getElementById(elementId).disabled=false;	
			
			}
		}
		
	function visibilityRuleControlFromAjaxResponse(visibilityRuleArray) {
		var fieldName = null;
		var visibilityRule = null;
		if (visibilityRuleArray != null && visibilityRuleArray.length > 0) {
			for (var i = 0; i < visibilityRuleArray.length; i++) {
				fieldName = visibilityRuleArray[i].fieldName;				
				visibilityRule = visibilityRuleArray[i].visibilityRule;
				var elementArray = document.getElementsByName(fieldName);
				if(elementArray==null || elementArray.length==0){//<label> element has no name attr
					var elementObj=document.getElementById(fieldName);
					if(elementObj!=null){
						elementArray=new Array();
						elementArray[0]=elementObj;
					}
				}
				//alert("fieldName is :"+fieldName+",visibilityRule is:"+visibilityRule);
				if (elementArray != null && elementArray.length > 0) {
					for (var j = 0; j < elementArray.length; j++) {
						if (visibilityRule == "ro") { //read only
							elementArray[j].disabled = true;
							if (elementArray[j].style.display == "none") {
								elementArray[j].style.display = "inline";
							}							
						} else if (visibilityRule == "hidden") { //hidden
							elementArray[j].style.display = "none";
							//alert("hidded");
						} else if (visibilityRule == "rw") {
							if (elementArray[j].style.display == "none") {
								elementArray[j].style.display = "inline";
							}
							elementArray[j].disabled = false;
						}
					}
				}
			}
		}
	}		
	
	function getSelectedRadioValue(radioName) {
		var radioValue = null;
		var radioes = document.getElementsByName(radioName);
		if (radioes == null) {
			return null;
		}
		for (var i = 0; i < radioes.length; i++) {
			if (radioes[i].checked) {
				radioValue = radioes[i].value;
			}
		}
		return radioValue;
	}	
	
	function getSelectedCheckboxValueArray(checkBoxName){
		var valueArray=new Array();
		var boxes = document.getElementsByName(checkBoxName);
        for (var j = 0; j < boxes.length; j++) {
            if (boxes[j].checked) {
                valueArray[valueArray.length]=boxes[j].value;
            }
        }	
        return valueArray;
	}	
	
	var helpDialogRequestTime=0;
	var helpDialog=null;
	function showHelpDialog(dialogUrl){
		helpDialogRequestTime++;
		//var dialogUrl="https://w3alpha-2.toronto.ca.ibm.com/tools/ait/announce.nsf/vwWebAccessDocsByTopicID/AnnouncementPage?OpenDocument&mode=popup";
		if(helpDialog==null){	
			if(helpDialogRequestTime==1){//when double clcik,the helpDialog is sitll null after first click. but now should not open another window
				helpDialog=window.open(dialogUrl,"_blank", 'toolbar=0,scrollbars=1,resizable=1,location=0,menubar=0,width=525,height=400'); 		
			}
		}else if(helpDialog.closed){
			helpDialog=null;
			helpDialogRequestTime=0;
			return showHelpDialog(dialogUrl);			
		}else{
			helpDialog.focus();
		}
		return false;
	}
	
	
	//according to offer unid to get which row this offer locate.

	function getTableRowIdForSpecifiedValue( fieldName,fieldValue) {
		var radioes = document.getElementsByName(fieldName);
		var tempValue = "";
		if (radioes == null) {
			return -1;
		}
		var tableRowId = -1;
		for (var i = 0; i < radioes.length; i++) {
			tempValue = radioes[i].value;
			if (tempValue == fieldValue) {
				tableRowId = i;
				break;
			}
		}
		return tableRowId;
	}	
	
	function setSelectItem(selectid, v) {
		var isFound=false;
		var selectid = document.getElementById(selectid);
		for (var i = 0; i < selectid.options.length; i++) {
			if (selectid.options[i].value == v) {
				selectid.options[i].selected = true;
				isFound=true;
				break;
			}
		}
		return isFound;
	}	
	
	function setSelectRadio(objId,objValue){
		var isFound=false;
		var objectArray = document.getElementsByName(objId);
		if(objectArray==null){
			return isFound;
		}
        for (var i = 0; i < objectArray.length; i++) {
            if (objectArray[i].value==objValue) {
                objectArray[i].checked=true;
                isFound=true;
                break;
            }
        }	
        return isFound;
	}
	
	function setSelectCheckbox(objId,objValue){
		var isFound=false;
		var objectArray = document.getElementsByName(objId);
		if(objectArray==null){
			return isFound;
		}
        for (var i = 0; i < objectArray.length; i++) {
            if (objectArray[i].value==objValue) {
                objectArray[i].checked=true;
                isFound=true;
                break;
            }
        }	
        return isFound;
	}	
	
	function getPopupFeautures(intWidth, intHeight) {
	    var intLeftPos = (screen.width) ? (screen.width - intWidth) / 2 : 0;
	    var intTopPos = (screen.height) ? (screen.height - intHeight) / 2 : 0;
	    var features;
	    if (webbrowserType().indexOf("msie")> -1){
	       features = 'height=' + intHeight + ',width=' + intWidth + ',top=' + intTopPos + ',left=' + intLeftPos + ',resizable=yes,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes';
	  	}else{
	  	   features = 'height=' + intHeight + ',width=' + intWidth + ',top=' + intTopPos + ',left=' + intLeftPos + ',dialog=yes,modal=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes';
	  	}
	    return features
	}	
	
	function getPopupFeauturesWithLoc(xPosPrecent,yPosPrecent,intWidth, intHeight) {
		 var intLeftPos = 0;
		 var intTopPos = 0;
		if(xPosPrecent<=1){
			intLeftPos = (screen.width) ? (screen.width*xPosPrecent) : 0;
		}else{
			intLeftPos = xPosPrecent;
		}
		if(yPosPrecent<=1){
			intTopPos = (screen.height) ? (screen.height*yPosPrecent) : 0;
		}else{
			intTopPos = yPosPrecent;
		}		
	    var features=null;
	    if (webbrowserType().indexOf("msie")> -1){
	       features = 'height=' + intHeight + ',width=' + intWidth + ',top=' + intTopPos + ',left=' + intLeftPos + ',resizable=yes,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes';
	  	}else{
	  	   features = 'height=' + intHeight + ',width=' + intWidth + ',top=' + intTopPos + ',left=' + intLeftPos + ',dialog=yes,modal=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes';
	  	}
	    return features
	}	
		
	function getRandomCode(codeLength){
		var randomCharArray="0123456789abcdefghijklmnopqrstuvwxyz";	
		var min=0;
		var max=randomCharArray.length-1;
		var randomCodde="";
		for(var i=0;i<codeLength;i++){
			var id=parseInt(Math.random()*(max-min+1)+min);
			randomCodde+=randomCharArray.charAt(id);
		}
		//alert("randomCodde: "+randomCodde);
		return randomCodde;
	}
	  
	function isNumAndAlpha(s) {
		//^[A-Za-z0-9]+$
	    var validChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		return isCharsInBag(s,validChars);
	    return false;
	}  
			